package com.zhou;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Date: 2020-05-06 10:07
 * @version: 1.0
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line1[] = br.readLine().split(" ");
        int N = Integer.valueOf(line1[0]);
        int D = Integer.valueOf(line1[1]);
        String line2[] = br.readLine().split(" ");
        int loc[] = new int[N];
        for (int i = 0; i < N; i++)
            loc[i] = Integer.valueOf(line2[i]);
        long count = 0L;
        int right = 2;
        for (int i = 0; i < N - 2; i++) {
            long temp = 0L;
            int j = right;
            for (; j < N && loc[j] - loc[i] <= D; j++) ;
            temp = j - 1 - i;
            if (temp >= 2)
                count += temp * (temp - 1) / 2;
            if (count >= 99997867)
                count %= 99997867;
            right = j;
        }
        System.out.println(count);
    }
}
